package me.alide.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import me.alide.common.utils.PageUtils;
import me.alide.common.utils.Query;


import me.alide.modules.sys.dao.InformationEntityDao;
import me.alide.modules.sys.entity.InformationEntity;
import me.alide.modules.sys.redis.SysConfigRedis;
import me.alide.modules.sys.service.InformationService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class InformationServiceImpl extends ServiceImpl<InformationEntityDao,InformationEntity>implements InformationService{
    @Resource
    private InformationEntityDao informationEntityDao;
    @Autowired
    private SysConfigRedis sysConfigRedis;

    @Override
    public List<InformationEntity> queryAll() {
        return informationEntityDao.queryAll();
    }

    @Override
    public IPage<InformationEntity> show(int page, int pageSize) {
          IPage<InformationEntity> iPage =new Page<>(page,pageSize);
          QueryWrapper<InformationEntity> queryWrapper = new QueryWrapper<>();
           return informationEntityDao.selectPage(iPage,queryWrapper);
    }

    @Override
    public PageUtils query(Map<String, Object> params) {
        String paramKey = (String) params.get("paramKey");
        IPage<InformationEntity> iPage =this.page(
                new Query<InformationEntity>().getPage(params),
                new QueryWrapper<InformationEntity>()
                        .like(StringUtils.isNotBlank(paramKey),"org_name",paramKey)
        );
        return new PageUtils(iPage);
    }

    @Override
    public int saveInfo(InformationEntity info) {
          return informationEntityDao.insert(info);
    }

    @Override
    public int update(InformationEntity info) {
       return informationEntityDao.updateById(info);
    }

    @Override
    public int delete(Long[] ids) {
        LambdaQueryWrapper<InformationEntity> wrapper= Wrappers.lambdaQuery();
        wrapper.in(InformationEntity::getId, ids);
        return informationEntityDao.delete(wrapper);

    }
}
